import axios from "axios";
const isDev = process.env.NODE_ENV === 'development' // 真 - 开发环境，假-生产环境
const instance = axios.create({
    baseURL: isDev ? "http://47.94.6.186:3001/api" : "http://47.94.6.186:3001/api",
    timeout: 10000,
    headers: {
        "Content-Type": "application/json"
    }
});
instance.interceptors.request.use(config => {
    // 在发送请求之前做些什么
    // 例如添加认证token
    const token = localStorage.getItem("token");
    if (token) {
        config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
});

instance.interceptors.response.use(response => {
    // 对响应数据做点什么
    // 例如处理错误状态码
    if (response.status !== 200) {
        console.error("请求错误:", response);
    }
    // 处理成功的响应
    return response.data;
});
export default instance;
